int yuShuiTou=A8;  //雨水感应头
int yuShuiDianZu=0;  //雨水电阻值

int tuRangTou_1=A9;  //土壤感应头1
int tuRangTou_2=A10;  //土壤感应头2
int tuRangDianZu_1=0;  //土壤电阻值1
volatile byte tuRangShiDu_1=0;  //土壤湿度2
int tuRangDianZu_2=0;  //土壤电阻值1
volatile byte tuRangShiDu_2=0;  //土壤湿度2

int shuiWei_Gao_Tou=A11;  //水箱高水位探头
int shuiWei_Di_Tou=A12;  //水箱低水位探头
volatile int shuiWei_Man;  //水箱满
volatile int shuiWei_Kong;  //水箱空

//电压
float dianYa_taiYangNeng;
float dianYa_dianChi;
float dianYa_zhuBan;


#define ziLaiShui_Ji 2  //自来水流量计
#define guanGai_Ji 3  //灌溉流量计
#define RELAY_0 7  //自来水电磁阀
#define RELAY_1 6  //雨水泵和电磁阀
#define RELAY_2 5  //菜园_1灌溉泵和电磁阀
#define RELAY_3 4  //菜园_2灌溉泵和电磁阀

//dth11声明函数
#include<dht11.h>
dht11 DHT11;
#define DHT11PIN A5  // 设置 DHT 引脚 为 Pin A5

//webServer声明函数
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 111);
EthernetServer server(80);

void setup() {
  Serial.begin(9600);
  pinMode(RELAY_0,OUTPUT);
  pinMode(RELAY_1,OUTPUT);
  pinMode(RELAY_2,OUTPUT);
  pinMode(RELAY_3,OUTPUT);
  pinMode(shuiWei_Gao_Tou,INPUT);
  pinMode(shuiWei_Di_Tou,INPUT);
  pinMode(tuRangTou_1,INPUT);
  pinMode(tuRangTou_2,INPUT);

  pinMode(A15,INPUT);
  pinMode(A14,INPUT);
  pinMode(A13,INPUT);
  
//  pinMode(ziLaiShui_Ji,INPUT);
//  pinMode(guanGai_Ji,INPUT);

  

  
  
  //土壤湿度检测
  //tuRang();
  
  //webServerSetup
  webServerSetup();
  /*
  //自来水流量统计
  pinMode(ziLaiShui_Ji,INPUT);
  attachInterrupt(ziLaiShui_Ji,zi_LiuLiang,LOW);
  //灌溉流量统计
  pinMode(guanGai_Ji,INPUT);
  attachInterrupt(guanGai_Ji,guan_LiuLiang,LOW);
  */
  
}

void loop() {
  qiWen();
  Serial.println("-----------------------------------------");
  yuShuiShouJi();
  Serial.println("-----------------------------------------");
  ziLaiShui();
  Serial.println("-----------------------------------------");
  tuRang();
  Serial.println("-----------------------------------------");
  guanGai();
  Serial.println("-----------------------------------------");
  dianYa();
  Serial.println("-----------------------------------------");
  webServer();
//  ziLaiShui_LiuLiang();
 // guanGai_LiuLiang();  
  //Serial.println("\n");
  //Serial.println("-----------------------------------------");
  delay(2000);
  
}
